﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace SmsUI
{
    public partial class frmTrueTel : DevExpress.XtraEditors.XtraUserControl
    {
        private string trueNumFile = "c:\\TrueNum.txt";
        private string untrueNumFile = "c:\\UnTrueNum.txt";
        private string numFile = "c:\\waitToTrue.txt";
        private bool hasLoad = false;
        protected List<ListViewItem> CurrentCacheItemsSource
        {
            get;
            private set;
        }
        protected List<ListViewItem> SuCurrentCacheItemsSource
        {
            get;
            private set;
        }
        protected List<ListViewItem> UnCurrentCacheItemsSource
        {
            get;
            private set;
        }
        protected List<ListViewItem> ItemsSource
        {
            get;
            private set;
        }
        protected List<ListViewItem> SuItemsSource
        {
            get;
            private set;
        }
        protected List<ListViewItem> UnItemsSource
        {
            get;
            private set;
        }
        //DataBase.smsdbDataSet.tb_CheckListDataTable unCheckTb
        //{
        //    get
        //    {
        //        return DbRules.Instance.GetUnCheckedListTable();
        //    }
        //}
        //DataBase.smsdbDataSet.tb_CheckListDataTable CheckTb
        //{
        //    get
        //    {
        //        return DbRules.Instance.GetCheckedListTable();
        //    }
        //}
        public frmTrueTel()
        {
            InitializeComponent();
            btnStop.Enabled = false;
            ItemsSource = new List<ListViewItem>();
            CurrentCacheItemsSource = new List<ListViewItem>();
            SuItemsSource = new List<ListViewItem>();
            UnItemsSource = new List<ListViewItem>();
            SuCurrentCacheItemsSource = new List<ListViewItem>();
            UnCurrentCacheItemsSource = new List<ListViewItem>();
        }
        private void SuLoadListViewItems(List<ListViewItem> items)
        {
            lvObjectNo.Items.Clear();
            if (items == null)
            {
                lbSu.Text = "当前总共记录数为：0";
                return;
            }
            lvObjectNo.Scrollable = true;
            lvObjectNo.Visible = true;
            lvObjectNo.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(SulsvSendList_RetrieveVirtualItem);
            lvObjectNo.VirtualListSize = items.Count;//设置虚拟列表容量大小
            lvObjectNo.VirtualMode = true;
            lbSu.Text = "当前总共记录数为：" + items.Count;

        }
        private void UnLoadListViewItems(List<ListViewItem> items)
        {

            lvUnNo.Items.Clear();
            if (items == null)
            {
                lbUn.Text = "当前总共记录数为：0";
                return;
            }
            lvUnNo.Scrollable = true;
            lvUnNo.Visible = true;
            lvUnNo.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(UnlsvSendList_RetrieveVirtualItem);
            lvUnNo.VirtualListSize = items.Count;//设置虚拟列表容量大小
            lvUnNo.VirtualMode = true;
            lbUn.Text = "当前总共记录数为：" + items.Count;

        }

        private void LoadListViewItems(List<ListViewItem> items)
        {
            lvSourceNo.Items.Clear();
            if (items == null)
            {
                stripStatusInfo.Text = "当前总共记录数为：0";
                return;
            }
            lvSourceNo.Scrollable = true;
            lvSourceNo.Visible = true;
            lvSourceNo.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(lsvSendList_RetrieveVirtualItem);
            lvSourceNo.VirtualListSize = items.Count;//设置虚拟列表容量大小
            lvSourceNo.VirtualMode = true;
            stripStatusInfo.Text = "当前总共记录数为：" + items.Count;


        }

        void lsvSendList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            if (this.CurrentCacheItemsSource == null || this.CurrentCacheItemsSource.Count == 0)
            {
                return;
            }

            e.Item = this.CurrentCacheItemsSource[e.ItemIndex];
            if (e.ItemIndex == this.CurrentCacheItemsSource.Count)
            {
                this.CurrentCacheItemsSource = null;
            }
        }
        void SulsvSendList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            if (this.SuCurrentCacheItemsSource == null || this.SuCurrentCacheItemsSource.Count == 0)
            {
                return;
            }

            e.Item = this.SuCurrentCacheItemsSource[e.ItemIndex];
            if (e.ItemIndex == this.SuCurrentCacheItemsSource.Count)
            {
                this.SuCurrentCacheItemsSource = null;
            }
        }
        void UnlsvSendList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            if (this.UnCurrentCacheItemsSource == null || this.UnCurrentCacheItemsSource.Count == 0)
            {
                return;
            }

            e.Item = this.UnCurrentCacheItemsSource[e.ItemIndex];
            if (e.ItemIndex == this.UnCurrentCacheItemsSource.Count)
            {
                this.UnCurrentCacheItemsSource = null;
            }
        }
        private void frmTrueTel_Load(object sender, EventArgs e)
        {
            hasLoad = true;
            try
            {
                FileStream aFile = new FileStream(trueNumFile, FileMode.OpenOrCreate, FileAccess.Read);
                using (StreamReader sr = new StreamReader(aFile))
                {
                    string strLine = sr.ReadLine();

                    while (strLine != null)
                    {


                        strLine.Trim();
                        if (!string.IsNullOrEmpty(strLine))
                        {
                            this.SuItemsSource.Add(new ListViewItem(strLine));
                        }
                        strLine = sr.ReadLine();
                    }
                }
                aFile.Close();
            }
            catch
            {
            }
            try
            {
                FileStream aFile = new FileStream(untrueNumFile, FileMode.OpenOrCreate, FileAccess.Read);
                using (StreamReader sr = new StreamReader(aFile))
                {
                    string strLine = sr.ReadLine();

                    while (strLine != null)
                    {


                        strLine.Trim();
                        if (!string.IsNullOrEmpty(strLine))
                        {
                            this.UnItemsSource.Add(new ListViewItem(strLine));
                        }
                        strLine = sr.ReadLine();
                    }
                }
                aFile.Close();
            }
            catch
            {
            }

            try
            {
                FileStream aFile = new FileStream(numFile, FileMode.OpenOrCreate, FileAccess.Read);
                using (StreamReader sr = new StreamReader(aFile))
                {
                    string strLine = sr.ReadLine();

                    while (strLine != null)
                    {
                        strLine.Trim();

                        if (!string.IsNullOrEmpty(strLine))
                        {
                            this.ItemsSource.Add(new ListViewItem(strLine));
                        }
                        strLine = sr.ReadLine();
                    }
                }
                aFile.Close();
            }
            catch
            {
            }
            CurrentCacheItemsSource = ItemsSource;
            LoadListViewItems(CurrentCacheItemsSource);

            SuCurrentCacheItemsSource = SuItemsSource;
            SuLoadListViewItems(SuCurrentCacheItemsSource);

            UnCurrentCacheItemsSource = UnItemsSource;
            UnLoadListViewItems(UnCurrentCacheItemsSource);

        }

        public bool isnullorint(string str)
        {
            bool isint = true;
            if (str == "")
                str = "0";
            try
            {
                Int64 strint = Int64.Parse(str);
            }
            catch (FormatException e)
            {
                string str1;
                str1 = e.ToString();
                return false;
            }
            return isint;
        }

        private void setSourceCountlbl()
        {
            stripStatusInfo.Text = "当前原始号码框中有" + lvSourceNo.Items.Count.ToString() + "个号码。";
        }
        private void setObjectCountlbl()
        {
            lblObjectCount.Text = "当前目标号码框中有" + lvObjectNo.Items.Count.ToString() + "个号码。";
        }

        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            //提示文件类型和格式
            //Magus.frmFileMessage frm1 = new Magus.frmFileMessage();
            //frm1.Owner = this;
            //frm1.ShowDialog();
            OpenFileDialog opendlg = new OpenFileDialog();

            opendlg.Title = "打开文本文件";
            opendlg.Filter = "文本文件 (*.txt)|*.txt";
            if (opendlg.ShowDialog() == DialogResult.OK)
            {
                lock (GetNumLock)
                {
                    string filename = opendlg.FileName;
                    string strLine;
                    try
                    {
                        //lvSourceNo.BeginUpdate();
                        using (FileStream aFile = new FileStream(filename, FileMode.Open, FileAccess.Read))
                        {
                            using (StreamReader sr = new StreamReader(aFile))
                            {
                                strLine = sr.ReadLine();
                                FileStream wFile = new FileStream(numFile, FileMode.Append, FileAccess.Write);
                                StreamWriter wsw = new StreamWriter(wFile);


                                while (strLine != null)
                                {
                                    strLine = strLine.Trim();
                                    wsw.WriteLine(strLine);
                                    if (!string.IsNullOrEmpty(strLine))
                                    {

                                        CurrentCacheItemsSource.Add(new ListViewItem() { Text = strLine, Tag = "0" });
                                    }
                                    //读下一行
                                    strLine = sr.ReadLine();
                                }
                                wsw.Close();
                                wFile.Close();
                            }
                        }

                    }
                    catch (Exception ex)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show(ex.ToString());
                        return;
                    }
                    finally
                    {
                        // lvSourceNo.EndUpdate();
                    }
                }
                Invalidat();
                //DbRules.Instance.UpdateUnCheckList();
            }
            //更新号码数量标签
            setSourceCountlbl();
            setObjectCountlbl();
        }
        public void Invalidat()
        {

            lvSourceNo.VirtualListSize = CurrentCacheItemsSource.Count;
            lvSourceNo.Invalidate();
            stripStatusInfo.Text = "当前原始号码框中有" + CurrentCacheItemsSource.Count + "号码";
        }
        public void SuInvalidat()
        {

            lvObjectNo.VirtualListSize = SuCurrentCacheItemsSource.Count;
            lvObjectNo.Invalidate();
            lbSu.Text = "当前有效号码框中有" + SuCurrentCacheItemsSource.Count + "号码";
        }
        public void UnInvalidat()
        {

            lvUnNo.VirtualListSize = UnCurrentCacheItemsSource.Count;
            lvUnNo.Invalidate();
            lbUn.Text = "当前有效号码框中有" + UnCurrentCacheItemsSource.Count + "号码";
        }
        //号码排序
        private void btnOrderObject_Click(object sender, EventArgs e)
        {
            lvObjectNo.Sorting = SortOrder.Ascending;
            DbRules.Instance.GetUnCheckedNumList().Sort();
            lvObjectNo.Sort();
        }
        //号码乱序
        private void btnUnOrder_Click(object sender, EventArgs e)
        {
            lvObjectNo.Sorting = SortOrder.None;
            lvObjectNo.Sort();
        }
        //根据文本文件滤除号码
        private void btnFilter_Click(object sender, EventArgs e)
        {
            //Magus.frmFileMessage frm1 = new Magus.frmFileMessage();
            //frm1.Owner = this;
            //frm1.ShowDialog();
            OpenFileDialog opendlg = new OpenFileDialog();
            opendlg.Title = "根据文本文件滤除号码";
            opendlg.Filter = "文本文件 (*.txt)|*.txt";
            if (opendlg.ShowDialog() == DialogResult.OK)
            {
                string filename = opendlg.FileName;
                string strLine;
                string strAll = "";
                try
                {
                    FileStream aFile = new FileStream(filename, FileMode.Open, FileAccess.Read);
                    StreamReader sr = new StreamReader(aFile);
                    strLine = sr.ReadLine();
                    strAll += strLine + ",";
                    while (strLine != null)
                    {
                        strLine.Trim();
                        strAll += strLine + ",";
                        //读下一行
                        strLine = sr.ReadLine();
                    }
                    sr.Close();

                }
                catch (IOException ef)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ef.ToString());
                    return;
                }
                foreach (ListViewItem it in lvObjectNo.Items)
                {
                    strLine = it.Text;
                    //读下一行
                    if (strAll.IndexOf(strLine) >= 0)
                    {
                        it.Remove();
                    }
                }
            }
            //更新号码数量标签
            setSourceCountlbl();
            setObjectCountlbl();
        }
        //消除重号
        private void btnDelRepeat_Click(object sender, EventArgs e)
        {
            if (lvObjectNo.Items.Count < 2)
            {
                return;
            }
            //被比对的it首先定位第一个，从第2个开始循环与其比对
            ListViewItem it = lvObjectNo.Items[0];
            int k = 1;

            while (k < lvObjectNo.Items.Count)
            {
                for (int i = k; i < lvObjectNo.Items.Count; i++)
                {
                    //随着Remove操作，Count会变小，如果超出范围，打破循环
                    if (i >= lvObjectNo.Items.Count)
                        break;
                    if (lvObjectNo.Items[i].Text.Equals(it.Text))
                    {
                        lvObjectNo.Items[i].Remove();
                    }
                }
                //随着Remove操作，Count会变小，如果超出范围，无需再赋值
                //不超出范围，则被比对的it后移一位，开始比对的地方也后移1位
                if (k < lvObjectNo.Items.Count)
                    it = lvObjectNo.Items[k];
                k++;
            }
            //更新号码数量标签
            setSourceCountlbl();
            setObjectCountlbl();
        }
        //保存号码到文本文件
        private void btnSaveNo_Click(object sender, EventArgs e)
        {
            if (!(lvObjectNo.Items.Count > 0))
            {
                return;
            }
            SaveFileDialog saveDlg = new SaveFileDialog();
            saveDlg.Title = "保存号码到文本文件";
            saveDlg.Filter = "文本文件 (*.txt)|*.txt";
            if (saveDlg.ShowDialog() == DialogResult.OK)
            {
                string filename = saveDlg.FileName;
                string strLine;
                try
                {
                    FileStream aFile = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(aFile);
                    foreach (ListViewItem it in this.SuCurrentCacheItemsSource)
                    {
                        strLine = it.Text;
                        //读下一行
                        sw.WriteLine(strLine);
                    }
                    sw.Close();

                }
                catch (IOException ef)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ef.ToString());
                    return;
                }
            }
            //更新号码数量标签
            setSourceCountlbl();
            setObjectCountlbl();
        }


        //开始检测
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (SmsHelper.SmsHelper.Instance.IsSendFlag)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("请停止发送短信再开始号码真经检测！");
                return;
            }
            //首先得到设备信息
            //  getSetInfo();
            //打开端口，如果不成功，提示检测设备，如果成功则检测电话号码
            if (this.lvSourceNo.Items.Count <= 0)
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("要检测的手机号码不能为空，请先导入号码文件！", "提示", MessageBoxButtons.OK);
                return;
            }
            SmsHelper.SmsHelper.Instance.IsCallFlag = true;
            if (SmsHelper.SmsHelper.Instance.AsynCheckNum())
            {

                FormManager.Instance.MainForm.UIStartSend();
                btnStart.Enabled = false;
                btnStop.Enabled = true;
            }
            else
            {
                SmsHelper.SmsHelper.Instance.IsCallFlag = false;
            }
            //  lblLog.Text = "Log:检测完成！";
        }
        private static object GetNumLock = new object();
        public void SaveUnDetectNum()
        {
            if (!hasLoad)
            {
                return;
            }

            try
            {
                File.Delete(numFile);
            }
            catch
            {
            }
            FileStream aFile = new FileStream(numFile, FileMode.OpenOrCreate, FileAccess.Write);
            string strLine = "";
            using (StreamWriter sw = new StreamWriter(aFile))
            {
                foreach (ListViewItem it in this.CurrentCacheItemsSource)
                {
                    strLine = it.Text;
                    if (!string.IsNullOrEmpty(strLine))
                    {
                        //读下一行
                        sw.WriteLine(strLine);
                    }
                }
            }
            aFile.Close();


        }
        public string GetANum()
        {


            string num = "";
            this.Invoke(new MethodInvoker(() =>
            {
                ListViewItem item = null;
                lock (GetNumLock)
                {
                    for (int i = 0; i < CurrentCacheItemsSource.Count; i++)
                    {
                        item = CurrentCacheItemsSource[i];

                        num = item.Text;
                        CurrentCacheItemsSource.Remove(item);
                        Invalidat();
                        break;
                    }
                }
            }));

            return num;
        }
        //判断是否有可启动设备信息，如果为空，则默认使用COM1口。
        private void getSetInfo()
        {

        }

        public bool InitCom(string m_port, int m_baudrate)
        {

            return true;
        }
        //发送ATD命令给TelNo，如果在规定时间内没有回复数据，表示有效，如果回复有数据，判断数据并得到是否有效
        private bool ATDTel(string TelNo)
        {
            //bool isSucc = false;
            //string readBuffer = "";
            //int retryTimeOut = 500;

            //#region 用ATD指令检测号码是否有效
            //ss_port.Write(Encoding.ASCII.GetBytes(String.Format("ATD {0};\r", TelNo)));

            ///***
            // *                                        规定时间内没有返回值，有效，还没有人接听
            // * OK                 0                   呼叫成功 仅对语音呼叫 接通
            // * CONNECT<speed>     10,11,12,13,14,15   呼叫成功 对数据电话<speed>采用模块协商后的值
            // * BUSY               7                   被叫方忙（被挂断10秒后才返回本值）
            // * NO ANSWER          8                   固定连接时间到后未检测到挂起信号（响铃30多秒没接听时返回）
            // * NO CARRIER         3                   呼叫建立失败或远端用户已释放 （没信号、空号时23秒后才返回）
            // * 
            // * 发送拨号命令后立即使用at+clcc命令查看目前状态，根据返回值判断是否有效
            // * +CLCC: 1,0,3,0,0,"13911078327",129（振铃时<stat>=3），出现了振铃状态，立即发送ATH挂断，为有效
            // * （+CLCC: 1,0,2,0,0,"13911078327",129）还未振铃时<stat>=2
            // * （+CLCC: 1,0,2,0,0,"17711078327",129）还未振铃时<stat>=2，无效号码一直都时这个返回值，直到返回了NO CARRIER，或者响应CLCC返回了ERROR
            // * 如果一直是未振铃状态，未等到振铃返回了NO CARRIER，或者响应返回了ERROR，则表示无效号码
            // * */
            ////用AT+CLCC指令查看目前状态
            //while (true)
            //{
            //    ss_port.Write(Encoding.ASCII.GetBytes("AT+CLCC\r"));
            //    Thread.Sleep(retryTimeOut);
            //    readBuffer += Encoding.ASCII.GetString(ss_port.Read(128));
            //    //lblLog.Text = readBuffer;
            //    if ((readBuffer.IndexOf("+CLCC: 1,0,3") != -1) || (readBuffer.IndexOf("BUSY") != -1))
            //    {
            //        //一个正振铃的电话或被挂断的电话，号码有效
            //        isSucc = true;
            //        break;
            //    }
            //    else if (readBuffer.IndexOf("+CLCC: 1,0,2") != -1)  //一个正拨打的电话，还未振铃
            //    {
            //        readBuffer = "";
            //    }
            //    else if (readBuffer.IndexOf("+CLCC: 1,1,") != -1)   //有一个来电，挂断，继续判断
            //    {
            //        readBuffer = "";
            //        ss_port.Write(Encoding.ASCII.GetBytes("ATH\r"));
            //    }
            //    else if (readBuffer.IndexOf("OK") != -1)     //如果当前没有电话在工作，结束判断，无效号码
            //    {
            //        readBuffer = "";
            //        break;
            //    }
            //    else if ((readBuffer.IndexOf("NO CARRIER") != -1) || (readBuffer.IndexOf("ERROR") != -1))
            //    {
            //        //始终没有等到振铃，号码无效，结束判断
            //        break;
            //    }
            //}
            ////ATH 呼叫挂起
            //ss_port.Write(Encoding.ASCII.GetBytes("ATH\r"));
            //#endregion
            //return isSucc;
            return true;
        }
        private static readonly object listViewLock = new object();


        internal void AddUseNum(string num)
        {
            lock (listViewLock)
            {
                this.SuCurrentCacheItemsSource.Add(new ListViewItem(num));
                SuInvalidat();
                try
                {
                    FileStream aFile = new FileStream(trueNumFile, FileMode.Append, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(aFile);
                    sw.WriteLine(num);
                    sw.Close();
                }
                catch
                {

                }
            }
        }
        internal void AddUnUseNum(string num)
        {
            lock (listViewLock)
            {
                this.UnCurrentCacheItemsSource.Add(new ListViewItem(num));
                UnInvalidat();
                try
                {
                    FileStream aFile = new FileStream(untrueNumFile, FileMode.Append, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(aFile);
                    sw.WriteLine(num);
                    sw.Close();
                    aFile.Close();
                }
                catch
                {

                }
            }
        }
        internal void ReWrite()
        {
            //DbRules.Instance.GetUnCheckedNumList().Clear();
            //for (int i = 0; i < lvSourceNo.Items.Count; i++)
            //{
            //    DbRules.Instance.GetUnCheckedNumList().Add(lvSourceNo.Items[i].Text);
            //}
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            SmsHelper.SmsHelper.Instance.IsCallFlag = false;
            FormManager.Instance.MainForm.UIStopSend();
            SmsHelper.SmsHelper.Instance.ServiceStop();
            btnStart.Enabled = true;
            btnStop.Enabled = false;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if (DevExpress.XtraEditors.XtraMessageBox.Show("确认要清空列表嘛？", "清空 ", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation).Equals(DialogResult.OK))
            {
                try
                {
                    File.Delete(trueNumFile);
                }
                catch
                {
                }
                this.SuCurrentCacheItemsSource.Clear();
                SuInvalidat();
            }
        }

        private void btnClearSource_Click(object sender, EventArgs e)
        {
            try
            {
                File.Delete(numFile);
            }
            catch
            {
            }
            this.CurrentCacheItemsSource.Clear();

            Invalidat();
        }

        private void btnMI_Click(object sender, EventArgs e)
        {

            InputNum win = new InputNum("请输入号码：");

            win.ShowDialog();
            if (win.DialogResult == DialogResult.OK)
            {
                if (!string.IsNullOrEmpty(win.PhoneNum))
                {
                    lock (GetNumLock)
                    {

                        ListViewItem item = new ListViewItem { Text = win.PhoneNum, Tag = "0" };
                        CurrentCacheItemsSource.Insert(0, item);
                        Invalidat();

                    }


                }
            }

        }
        public void AddNum(string num)
        {
            lock (GetNumLock)
            {
                try
                {
                    FileStream aFile = new FileStream(numFile, FileMode.Append, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(aFile);
                    sw.WriteLine(num);
                    sw.Close();
                    aFile.Close();
                }
                catch
                {

                }
                ListViewItem item = new ListViewItem { Text = num, Tag = "0" };
                CurrentCacheItemsSource.Insert(0, item);
                Invalidat();

            }

        }
        private void btnUn_Click(object sender, EventArgs e)
        {

            if (!(lvUnNo.Items.Count > 0))
            {
                return;
            }
            SaveFileDialog saveDlg = new SaveFileDialog();
            saveDlg.Title = "保存号码到文本文件";
            saveDlg.Filter = "文本文件 (*.txt)|*.txt";
            if (saveDlg.ShowDialog() == DialogResult.OK)
            {
                string filename = saveDlg.FileName;
                string strLine;
                try
                {
                    FileStream aFile = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(aFile);
                    foreach (ListViewItem it in this.UnCurrentCacheItemsSource)
                    {
                        strLine = it.Text;
                        //读下一行
                        sw.WriteLine(strLine);
                    }
                    sw.Close();
                    aFile.Close();

                }
                catch (IOException ef)
                {
                    DevExpress.XtraEditors.XtraMessageBox.Show(ef.ToString());
                    return;
                }
            }

        }

        private void btnClearUn_Click(object sender, EventArgs e)
        {
            if (DevExpress.XtraEditors.XtraMessageBox.Show("确认要清空列表嘛？", "清空 ", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation).Equals(DialogResult.OK))
            {
                try
                {
                    File.Delete(untrueNumFile);
                }
                catch
                {
                }
                this.UnCurrentCacheItemsSource.Clear();
                UnInvalidat();
            }
        }
    }
    public class SendClass
    {
        public string PhoneNum { get; set; }
        public string ComPort { get; set; }
        public string Content { get; set; }
    }

}
